package com.wanghlme.leetcodecn;

/**
 * <p>剑指 Offer 11. 旋转数组的最小数字</p>
 * <p>JZ11->main0154</p>
 *
 * @author wanghlme
 * @version 1.0
 */
public class LC_JZ11 {
    public static void main(String[] args) {
        int[] arr = {2, 2, 2, 0, 1};
        System.out.println(new Solution().minArray(arr));
    }

    static class Solution {
        public int minArray(int[] numbers) {
            int l = 0;
            int r = numbers.length - 1;
            while (l < r) {
                int cur = l + (r - l) / 2;
                if (numbers[cur] < numbers[r]) {
                    r = cur;
                } else if (numbers[cur] > numbers[r]) {
                    l = cur + 1;
                } else {
                    r -= 1;
                }
            }
            return numbers[l];
        }
    }
}
